/**
 * @license
 * Copyright 2023 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @fileoverview Colour field test playground.
 */

import * as Blockly from 'blockly';
import {generateFieldTestBlocks, createPlayground} from '@blockly/dev-tools';
import '../src/index';

const toolbox = generateFieldTestBlocks('field_colour', [
  {
    label: 'Standard',
    args: {},
  },
  {
    label: 'Custom',
    args: {
      colour: '#ff4040',
      colourOptions: [
        '#ff4040',
        '#ff8080',
        '#ffc0c0',
        '#4040ff',
        '#8080ff',
        '#c0c0ff',
      ],
      colourTitles: [
        'dark pink',
        'pink',
        'light pink',
        'dark blue',
        'blue',
        'light blue',
      ],
      columns: 3,
    },
  },
]);

/**
 * Create a workspace.
 *
 * @param blocklyDiv The blockly container div.
 * @param options The Blockly options.
 * @returns The created workspace.
 */
function createWorkspace(
  blocklyDiv: HTMLElement,
  options: Blockly.BlocklyOptions,
): Blockly.WorkspaceSvg {
  const workspace = Blockly.inject(blocklyDiv, options);
  return workspace;
}

document.addEventListener('DOMContentLoaded', function () {
  const defaultOptions: Blockly.BlocklyOptions = {
    toolbox,
  };
  const rootElement = document.getElementById('root');
  if (rootElement) {
    createPlayground(rootElement, createWorkspace, defaultOptions);
  }
});
